package com.osmino.contacts.groups.add;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.widget.Checkable;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TwoLineListItem;
import com.osmino.contacts.R;

public class TwoLineListItemCheckable extends FrameLayout implements Checkable {

	protected final Context mContext;
	protected boolean mChecked;
	protected final TextView mText1, mText2;
	protected final RadioButton mRadioButton;

	public TwoLineListItemCheckable(Context context) {
		super(context);
		mContext = context;
		LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		layoutInflater.inflate(R.layout.two_text_checkable_item, this);
		mChecked = false;
		mText1 = (TextView) findViewById(R.id.text1);
		mText2 = (TextView) findViewById(R.id.text2);
		mText1.setTextColor(Color.BLACK);
		mText1.setTypeface(Typeface.DEFAULT);
		mText2.setTextColor(Color.BLACK);
		mText2.setTypeface(Typeface.DEFAULT);
		mRadioButton = (RadioButton) findViewById(R.id.filter_item_checkbox);
		setChecked(false);
	}

	@Override
	public boolean isChecked() {
		return mChecked;
	}

	@Override
	public void setChecked(boolean checked) {
		if (mChecked != checked) {
			mChecked = checked;
		}
		mRadioButton.setChecked(mChecked);
	}

	@Override
	public void toggle() {
		setChecked(!mChecked);
	}

	public void setText1(CharSequence text) {
		mText1.setText(text);
	}

	public void setText2(CharSequence text) {
		mText2.setText(text);
	}
}
